<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>商品分类管理</el-breadcrumb-item>
    </el-breadcrumb>

    <!-- 搜索筛选 -->
    <el-form :inline="true" :model="formInline" class="shangpinxinxi-search">
      <el-form-item label="">
<!--        <el-button size="small" type="warning" @click="handleBatchDel">批量删除</el-button>-->
      </el-form-item>

      <el-form-item label="分类名称">
        <el-input size="small" clearable v-model="formInline.categoryName" placeholder="输入分类名称"></el-input>
      </el-form-item>
      <el-form-item label="商品名称">
        <el-input size="small" clearable v-model="formInline.productName" placeholder="请输入商品名称"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button size="small" type="primary" icon="el-icon-search" @click="search">搜索</el-button>
<!--        <el-button size="small" type="primary" icon="el-icon-plus" @click="handleAdd()">添加</el-button>-->
      </el-form-item>
    </el-form>

    <!--列表-->
    <el-table size="small" @selection-change="handleSelectionChange" :data="listData" highlight-current-row
              v-loading="loading" border element-loading-text="拼命加载中" style="width: 100%;">
      <el-table-column align="center" type="selection" width="60">
      </el-table-column>
      <el-table-column sortable prop="shangpin.productId" label="商品编号">
      </el-table-column>
      <el-table-column sortable prop="shangpin.productName" label="商品名称">
      </el-table-column>
      <el-table-column sortable prop="categoryName" label="分类名称">
      </el-table-column>
      <el-table-column sortable prop="shangpin.productNumber" label="商品库存">
      </el-table-column>
      <el-table-column sortable prop="shangpin.productPrice" label="商品价格">
      </el-table-column>
      <el-table-column sortable prop="shangpin.productDescription" label="商品描绘">
      </el-table-column>
      <el-table-column sortable prop="shangpin.productStatus" label="商品状态">
      </el-table-column>
      <el-table-column sortable prop="shangpin.createdAt" label="创建时间">
      </el-table-column>
<!--      <el-table-column align="center" label="操作">-->
<!--        <template slot-scope="scope">-->
<!--          <el-button size="mini" @click="handleEdit(scope.$index, scope.row)">编辑</el-button>-->
<!--          -->
<!--          <el-button size="mini" type="danger" @click="deleteScore(scope.row.id)">删除</el-button>-->
<!--        </template>-->
<!--      </el-table-column>-->
    </el-table>


    <!-- 分页组件 -->
    <Pagination v-bind:child-msg="pageparm" v-model="pageparm" @callFather="callFather"></Pagination>


  </div>

</template>

<script>


import {shangpinxinxiList, shangpinfenleiStatus, shangpinfenleiSave, shangpinfenleiEdit, shangpinfenleiDelete, shangpinfenleiBatchDel} from '../../api/shangpinfenleiMG'


import Pagination from "../../components/Pagination";

export default {
  name: "shangpinxinxi",

  data(){

    return {

      formInline: {
        pageNum: 1,
        pageSize: 5,
        categoryName: '',
        productName: ''
      },
      editFormVisible: false, //控制编辑页面显示与隐藏
      title: '添加',

      // 分页参数
      pageparm: {
        currentPage: 1,
        pageSize: 10,
        total: 10
      },
      listData: [

      ],
      loading: false, //是显示加载
      multipleSelection: []
    }
  },
  components: {
    Pagination
  },
  /**
   * 创建完毕
   */
  created() {
    this.getdata(this.formInline)
  },
  methods:{
    getdata(formInline) {
      console.log(formInline)
      /***
       * 调用接口，注释上面模拟数据 取消下面注释
       */
      shangpinxinxiList(formInline)
        .then(res => {
          this.loading = false
          if (res.code != 20000) {
            this.$message({
              type: 'info',
              message: res.msg
            })
          } else {
            //  res == R 对象
            const pageInfo = res.data;

            this.listData = pageInfo.list;
            // 分页赋值
            this.pageparm.currentPage = this.formInline.pageNum
            this.pageparm.pageSize = this.formInline.pageSize
            this.pageparm.total = pageInfo.total
            console.log(this.pageparm)
          }
        })
        .catch(err => {
          this.loading = false
          this.$message.error('商品信息加载失败，请稍后再试！')
        })
    },
    closeDialog() {
      this.editFormVisible = false;
      this.getdata(this.formInline)
    },


    search() {
      console.log(this.formInline)
      this.getdata(this.formInline)
    },

    handleSelectionChange(val) {
      // val是数组,其中是前端框架自己封装的,其实是勾选的每一行数据对象
      console.log(val)
      var idArr = [];
      for (var i = 0; i < val.length; i++) {
        var obj = val[i];
        //console.log(obj)
        idArr.push(obj.productId);
      }
      console.log(idArr)

      this.multipleSelection = idArr;
    },

    callFather(pageparam) {

      console.log("callFather"+pageparam);

      this.formInline.pageNum = pageparam.pageNum;
      this.formInline.pageSize = pageparam.pageSize;
      this.getdata(this.formInline)
    },
  }
}
</script>

<style scoped>

</style>
